package com.health.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.health.system.entity.HealthRules;
import com.health.system.service.HealthRulesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author baomidou
 * @since 2024-06-22
 */
@Validated
@Api(tags = "健康规则管理")
@RestController
public class HealthRulesController {
    @Autowired
    private HealthRulesService healthRulesService;

    @ApiOperation(value = "查看全部健康规则")
    @GetMapping("/admin/health/rules")
    public IPage<HealthRules> getAllHealthRules(@RequestParam(value = "current", defaultValue = "1") Long current,
                                                @RequestParam(value = "size", defaultValue = "10") Long size) {
        return healthRulesService.getAllHealthRules(current, size);
    }

    @ApiOperation(value = "根据ID查询健康规则")
    @GetMapping("/admin/health/rules/{id}")
    public HealthRules getHealthRulesById(@PathVariable Integer id) {
        return healthRulesService.getHealthRulesById(id);
    }

    @ApiOperation(value = "新增健康规则")
    @PostMapping("/admin/health/rules")
    public void addHealthRules(@RequestBody HealthRules healthRules) {
        healthRulesService.addHealthRules(healthRules);
    }

    @ApiOperation(value = "修改健康规则")
    @PutMapping("/admin/health/rules")
    public void updateHealthRules(@RequestBody HealthRules healthRules) {
        healthRulesService.updateHealthRules(healthRules);
    }

    @ApiOperation(value = "删除健康规则")
    @DeleteMapping("/admin/health/rules/{id}")
    public void deleteHealthRules(@PathVariable Integer id) {
        healthRulesService.deleteHealthRules(id);
    }
}
